LAB 2 - Visualization of Packages¶

Importing of plotly¶

In [ ]:
import plotly
plotly.offline.init_notebook_mode()

Graph Creation From Different Tools¶

Matplotlib¶

I. bar(x, height)¶

In [ ]:
import matplotlib.pyplot as plt
import numpy as np

plt.style.use('_mpl-gallery')

# make data:
x = 0.5 + np.arange(8)
y = [4.8, 5.5, 3.5, 4.6, 6.5, 6.6, 2.6, 3.0]

# plot
fig, ax = plt.subplots()

ax.bar(x, y, width=1, edgecolor="white", linewidth=0.7)

ax.set(xlim=(0, 8), xticks=np.arange(1, 8),
       ylim=(0, 8), yticks=np.arange(1, 8))

plt.show()

This plot comes under Pairwise data which works by each alternative being compared against every other alternative in pairs.¶

II. pie(x)¶

In [ ]:
import matplotlib.pyplot as plt
import numpy as np

plt.style.use('_mpl-gallery-nogrid')


# make data
x = [1, 2, 3, 4]
colors = plt.get_cmap('Blues')(np.linspace(0.2, 0.7, len(x)))

# plot
fig, ax = plt.subplots()
ax.pie(x, colors=colors, radius=3, center=(4, 4),
       wedgeprops={"linewidth": 1, "edgecolor": "white"}, frame=True)

ax.set(xlim=(0, 8), xticks=np.arange(1, 8),
       ylim=(0, 8), yticks=np.arange(1, 8))

plt.show()

This plot comes under Statistical Distributions. Plots of the distribution of at least one variable in a dataset. Some of these methods also compute the distributions.¶

Seaborn Tool¶

I. Timeseries plot with error bands¶

In [ ]:
import seaborn as sns
sns.set_theme(style="darkgrid")

# Load an example dataset with long-form data
fmri = sns.load_dataset("fmri")

# Plot the responses for different events and regions
sns.lineplot(x="timepoint", y="signal",
             hue="region", style="event",
             data=fmri)
Out[ ]:
<Axes: xlabel='timepoint', ylabel='signal'>

The resulting plot displays how the "signal" variable changes over "timepoint" for different "events" and "regions."¶

II. FacetGrid - Facetting histograms by subsets of data¶

In [ ]:
import seaborn as sns

sns.set_theme(style="darkgrid")
df = sns.load_dataset("penguins")
sns.displot(
    df, x="flipper_length_mm", col="species", row="sex",
    binwidth=3, height=3, facet_kws=dict(margin_titles=True),
)
Out[ ]:
<seaborn.axisgrid.FacetGrid at 0x21b3434cc90>

Each subplot represents the distribution of "flipper_length_mm" for a specific combination of penguin species and sex. The x-axis represents "flipper_length_mm," and the y-axis represents the frequency of occurrences within each bin.¶

Plotly Express¶

I. Scatter Plots and Discrete Colour¶

In [ ]:
import plotly.express as px
df = px.data.iris()
fig = px.scatter(df, x="sepal_width", y="sepal_length", color="species")
fig.show()

To create a scatter plot of the Iris dataset, visualizing the relationship between sepal width and sepal length, with data points colored by the species of the iris flowers.¶

II. Barcharts¶

In [ ]:
import plotly.express as px
df = px.data.tips()
fig = px.bar(df, x="sex", y="total_bill", color="smoker", barmode="group")
fig.show()

The chart depicts the total bill amounts for different genders ("sex") in two separate groups based on smoking status ("smoker"), providing a visual comparison of total bills among different categories.¶

Additional Markdown Elements¶

I. Incorporating a hyperlink in Markdown¶

Click here to visit Google

II .Incorporating a table in Markdown¶

Stretch/Untouched ProbDistribution Accuracy
Stretched Gaussian .843

III. Incorporating an image in Markdown¶

In [ ]:
from PIL import Image
from matplotlib import pyplot as plt

img = Image.open('C:/CSCN8010-Lab/Desk/tree.jpg')
fig = plt.imshow(img)
plt.axis('off')
fig.axes.get_xaxis().set_visible(False)
fig.axes.get_yaxis().set_visible(False)

IV. Incorporating a Dynamic JS-based Graph¶

In [ ]:
px.scatter(x=[1, 2, 3], y=[1, 0, 3])